package com.yunhe.policyfulfillment.authority.controller;

import com.yunhe.common.exception.ArgumentErrorException;
import com.yunhe.common.model.ResultObject;
import com.yunhe.policyfulfillment.authority.domain.PolicyOrg;
import com.yunhe.policyfulfillment.authority.service.IPolicyOrgService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName PolicyOrgController
 * @Description TODO
 * @Author HeTao
 * @Date 2021/7/26 9:37
 * @Version 1.0
 **/
@RestController
@RequestMapping(value = "/policyOrg")
@Api(value = "PolicyOrg", description = "政策兑现后台组织", tags = {"Model_PolicyOrg"})
public class PolicyOrgController {

    @Autowired
    private IPolicyOrgService policyOrgService;

    /**
     * 查询所有组织
     * @author hetao
     * @date 2021/07/22
     **/
    @ApiOperation("查询所有组织")
    @GetMapping(value = "/findPolicyOrgs")
    public ResponseEntity<ResultObject<List<PolicyOrg>>> findPolicyOrgs(){
        return new ResponseEntity<>(new ResultObject(policyOrgService.findPolicyOrgs()), HttpStatus.OK);
    }

    @ApiOperation("根据组织类型查询组织")
    @GetMapping(value = "/findPolicyOrgsByOrgType")
    public ResponseEntity<ResultObject<List<PolicyOrg>>> findPolicyOrgsByOrgType(@RequestParam(value = "orgType",required = true) String orgType){
        return new ResponseEntity<>(new ResultObject(policyOrgService.findPolicyOrgsByOrgType(orgType)), HttpStatus.OK);
    }

    @ApiOperation("根据组织id查询组织")
    @GetMapping(value = "/findPolicyOrgByOrgId")
    public ResponseEntity<ResultObject<List<PolicyOrg>>> findPolicyOrgByOrgId(@RequestParam(value = "orgId",required = true) int orgId){
        return new ResponseEntity<>(new ResultObject(policyOrgService.findPolicyOrgByOrgId(orgId)), HttpStatus.OK);
    }

    @ApiOperation("获取党政办和主管部门")
    @GetMapping(value = "/findPartyGovernmentOfficeAndCompetentAuthority")
    public ResponseEntity<ResultObject<List<PolicyOrg>>> findPartyGovernmentOfficeAndCompetentAuthority(){
        return new ResponseEntity<>(new ResultObject(policyOrgService.findPartyGovernmentOfficeAndCompetentAuthority()), HttpStatus.OK);
    }

    @ApiOperation("新增组织")
    @PostMapping("/createPolicyOrg")
    public ResponseEntity<ResultObject> createOrg(@RequestBody PolicyOrg policyOrg) throws ArgumentErrorException {
        policyOrgService.createPolicyOrg(policyOrg);
        return new ResponseEntity<>(new ResultObject<>(), HttpStatus.OK);
    }

    @ApiOperation("根据id删除组织")
    @DeleteMapping("/deletePolicyOrg")
    public ResponseEntity<ResultObject> deletePolicyOrg(@RequestBody List<Long> ids) throws ArgumentErrorException {
        policyOrgService.deletePolicyOrg(ids);
        return new ResponseEntity<>(new ResultObject<>(), HttpStatus.OK);
    }

    @ApiOperation("更新组织")
    @PostMapping("/updatePolicyOrg")
    public ResponseEntity<ResultObject> updatePolicyOrg(@RequestBody PolicyOrg policyOrg) throws ArgumentErrorException {
        policyOrgService.updatePolicyOrg(policyOrg);
        return new ResponseEntity<>(new ResultObject<>(), HttpStatus.OK);
    }

}
